package cn.edu.gcu.lost.sys.entity;

import java.util.Date;
import java.util.List;

import org.springframework.format.annotation.DateTimeFormat;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.google.common.collect.Lists;

public class User extends BaseEntity{
	
	private static final long serialVersionUID = 1L;

	private String no;		// 工号
	
	@JsonIgnore
	private String password;// 密码
	private String name;	// 姓名
	private String email;	// 邮箱
	private String phone;	// 电话
	
	@JsonIgnore
	private String loginIp;	// 最后登陆IP
	
	@JsonIgnore
	private Date loginDate;	// 最后登陆日期
	
	@JsonIgnore
	private String loginFlag;	// 是否允许登陆

	private Role role;	// 根据角色查询用户条件
	
	@JsonIgnore
	private List<Role> roleList = Lists.newArrayList(); // 拥有角色列表

	public User() {
		super();
	}
	
	public User(String id) {
		super(id);
	}
	
	public User(String id,String no) {
		super();
		this.no = no;
	}
	
	public User(Role role) {
		super();
		this.role = role;
	}
	
	public String getNo() {
		return no;
	}

	public void setNo(String no) {
		this.no = no;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getEmail() {
		return email;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	public String getPhone() {
		return phone;
	}

	public void setPhone(String phone) {
		this.phone = phone;
	}

	public String getLoginIp() {
		return loginIp;
	}

	public void setLoginIp(String loginIp) {
		this.loginIp = loginIp;
	}

	public Date getLoginDate() {
		return loginDate;
	}

	public void setLoginDate(Date loginDate) {
		this.loginDate = loginDate;
	}

	public String getLoginFlag() {
		return loginFlag;
	}

	public void setLoginFlag(String loginFlag) {
		this.loginFlag = loginFlag;
	}

	public Role getRole() {
		return role;
	}

	public void setRole(Role role) {
		this.role = role;
	}

	public List<Role> getRoleList() {
		return roleList;
	}

	public void setRoleList(List<Role> roleList) {
		this.roleList = roleList;
	}

	@Override
	public String toString() {
		return "User [no=" + no + ", password=" + password + ", name=" + name + ", email=" + email + ", phone=" + phone
				+ ", loginIp=" + loginIp + ", loginDate=" + loginDate + ", loginFlag=" + loginFlag + ", role=" + role
				+ ", roleList=" + roleList + "]";
	}
	
	@JsonIgnore
	public boolean isAdmin(){
		return isAdmin(this.id);
	}
	
	@JsonIgnore
	public static boolean isAdmin(String id){
		return id != null && "1".equals(id);
	}
	
}
